<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<script src="../js/jquery-3.3.1.min.js"></script>
<%@include file="../common/head.jsp"%>
<script>

    function checkUserCode(billCode) {
        var flag = false;
        var msg = "请输入用户编码";
        if (billCode.value != '') {
            msg = "";
            $.ajax({
                type: "post", // 指定客户端向服务器端发送数据的方式
                url: "bill/showBillCount", // 向服务器请求的地址
                data: {// 向服务器发送的数据
                    "billCode": billCode.value
                },
                async: false,// 是否为同步,true(默认值):异步 false:同步
                success: function (data) {// 服务器成功给予客户端响应的数据 out.print();
                    msg = "可用";
                    if (data != '0') {
                        msg = "此编码已存在,不可用"
                    } else {
                        flag = true;
                    }
                }

            });
        }
        billCode.nextElementSibling.innerText = msg;
        return flag;
    }

    function checkDate() {
        var result = checkUserCode($("#billCode").get(0));
        return result;
    }
</script>
<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>订单管理页面 >> 订单添加页面</span>
    </div>
    <div class="providerAdd">
        <form:form modelAttribute="bill" id="billForm" name="billForm" method="post" action="bill/doAdd" onsubmit="return checkDate">
            <!--div的class 为error是验证错误，ok是验证成功-->
            <input type="hidden" name="method" value="add">
            <div class="">
                <label for="billCode">订单编码：</label>
                <input type="text" name="billCode" class="text" id="billCode" onblur="checkUserCode(this)" value="">
                <!-- 放置提示信息 -->
                <font color="red"></font>
            </div>
            <div>
                <label for="productName">商品名称：</label>
                <input type="text" name="productName" id="productName" value="">
                <font color="red"><form:errors path="productName"/> </font>
            </div>
            <div>
                <label for="productUnit">商品单位：</label>
                <input type="text" name="productUnit" id="productUnit" value="">
                <font color="red"></font>
            </div>
            <div>
                <label for="productCount">商品数量：</label>
                <input type="text" name="productCount" id="productCount" value="">
                <font color="red"></font>
            </div>
            <div>
                <label for="totalPrice">总金额：</label>
                <input type="text" name="totalPrice" id="totalPrice" value="">
                <font color="red"></font>
            </div>
            <div>
                <label>供应商：</label>
                <select name="provider.proId" id="providerId">
                    <c:if test="${requestScope.providerList != null }">
                        <option value="0">--请选择--</option>
                        <c:forEach items="${requestScope.providerList }" var="b" >
                            <option <c:if test="${b .proId == param['provider.proId'] }">selected</c:if>
                                    value="${b.proId}">${b.proName}</option>
                        </c:forEach>
                    </c:if>
                </select>
                <font color="red"></font>
            </div>
            <div>
                <label >是否付款：</label>
                <input type="radio" name="isPayment" value="1" checked="checked">未付款
                <input type="radio" name="isPayment" value="2" >已付款
            </div>
            <div class="providerAddBtn">
                <input type="submit" name="add" id="add" value="保存">
                <input type="button" id="back" onclick="history.back()" name="back" value="返回" >
            </div>
        </form:form>
    </div>
</div>
</section>
<%@include file="../common/foot.jsp" %>
